


/*function SeekAll()
{
  var argsArray=new Array();
  argsArray.push(newArg("Action","Seek"));
  sendRequest("../controller/controllerRutas.jsp",argsArray,show);
}
*/

function clear_fields(){
    document.getElementById("idvehicles").value="";
    document.getElementById("cost").value="";
    document.getElementById("departuretime").value="";
    document.getElementById("duration").value="";
    document.getElementById("origin").value="";
    document.getElementById("destination").value="";
}


function addroutes()
{
    
    var argsArray=new Array();
    argsArray.push(newArg("Action","Add"));
    var txtID=document.getElementById("idvehicles").value;
    argsArray.push(newArg("ID",txtID));
    var  txtCosto=document.getElementById("cost").value;
    argsArray.push(newArg("COST",txtCosto));
    var txtsalida=document.getElementById("departuretime").value;
    argsArray.push(newArg("SALIDA",txtsalida));
    var txtduracion=document.getElementById("duration").value;
    argsArray.push(newArg("DURACION",txtduracion));
    var txtorigen=document.getElementById("origin").value;
    argsArray.push(newArg("ORIGEN",txtorigen));
    var txtdestino=document.getElementById("destination").value;
    argsArray.push(newArg("DESTINO",txtdestino));
  //var argsStr=argsArray.join("&");

     //jConfirm('hola','Error', 'Error Dialog');
    //alert(argsStr);
   if(txtID != "" && txtCosto != "" && txtsalida != "" && txtduracion != ""  && txtorigen != "" && txtdestino!= ""){

    sendRequest("../controller/controllerRutas.jsp", argsArray,btnAdd_onclick_response);
}
else{
     jConfirm('Faltan datos por llenar o incorrectos','Error', 'Error Dialog');
}
}

function btnAdd_onclick_response()
{
  if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval("("+res+")");
      if(info.errorcode == 0){
        jAlert('Regitrado Correctamente','Ok', 'Success Dialog');
        clear_fields();
  }
      else{

          jConfirm('Error guardando datos','Error', 'Error Dialog');
      }
}
  }

}

function updateroute()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Update"));
  var txtID=document.getElementById("idvehicles").value;
    argsArray.push(newArg("ID",txtID));
    var  txtCosto=document.getElementById("cost").value;
    argsArray.push(newArg("COST",txtCosto));
    var txtsalida=document.getElementById("departuretime").value;
    argsArray.push(newArg("SALIDA",txtsalida));
    var txtduracion=document.getElementById("duration").value;
    argsArray.push(newArg("DURACION",txtduracion));
    var txtorigen=document.getElementById("origin").value;
    argsArray.push(newArg("ORIGEN",txtorigen));
    var txtdestino=document.getElementById("destination").value;
    argsArray.push(newArg("DESTINO",txtdestino));
    //var argsStr=argsArray.join("&");
    //alert(argsStr);
if(txtID != "" && txtCosto != "" && txtsalida != "" && txtduracion != "" && txtorigen != "" && txtdestino!= ""){

     sendRequest("../controller/controllerRutas.jsp", argsArray,btnUpdate_onclick_response);
}
else{
     jConfirm('Faltan datos por llenar o incorrectos','Error', 'Error Dialog');
}
   
}

function btnUpdate_onclick_response()
{
  if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval("("+res+")");
      if(info.errorcode == 0){
        jAlert('Se a Modificado Correctamente','Ok', 'Success Dialog');
       clear_fields();
    }
      else{
          jConfirm('Error Modificando los Datos','Error', 'Error Dialog');
  }
    }
  }

}

function deleteroute()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Delete"));
     var txtorigen=document.getElementById("origin").value;
    argsArray.push(newArg("ORIGIN",txtorigen.value));
    var txtdestino=document.getElementById("destination").value;
    argsArray.push(newArg("DESTINATION",txtdestino.value));
  // var argsStr=argsArray.join("&");
    //alert(argsStr);

    if(txtorigen != "" && txtdestino !="" ){
    sendRequest("../controller/controllerRutas.jsp",argsArray,btnDelete_onclick_response);
}
else{

        jConfirm('Debe Ingresar el  origen y el destino','Error', 'Error Dialog');
}
}
function btnDelete_onclick_response()
{
    if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval("("+res+")");
      if(info.errorcode == 0){
       jAlert('Se a Eliminado Correctamente','Ok', 'Success Dialog');
       clear_fields();
      }
      else{
       jConfirm('Error al Eliminar','Error', 'Error Dialog');
      }
    }
  }
}

function show()
{
    if (isValidResponse(this))
    {

        var res=this.responseText;
        alert(res);
     if(res!="")
    {
        alert(res);
        var info=eval("("+res+")");
        alert(info);
    }
    
    else
       window.alert("Not Found!!");
    }
}

// aca  vengo



function idvehicles(){
    var argsArray=new Array();
    argsArray.push(newArg("Action","Vehicles"));
    sendRequest("../controller/controllerRutas.jsp",argsArray,showidvehicles);
}


function showidvehicles(){
    if (isValidResponse(this))
    {
        var res=this.responseText;
        if(res!="")
        {
            var info=eval("("+res+")");
            if(info.errorcode == 0)
            {
                if(info.data.length<1){
                    jConfirm('No hay id disponibles', 'Error', 'Error Dialog');
                }else{
                    var selF = document.getElementById("idvehicles");
                    var selectF = "";
                    for(var i=0; i<info.data.length; i++){
                        selectF+='<option>';
                        selectF+=info.data[i].i+'</option>';
                    }
                    selF.innerHTML = selectF;
                }

            }else
                jConfirm('No Found','Error', 'Error Dialog');
        }
    }

}


function cityorigin(){
    var argsArray=new Array();
    argsArray.push(newArg("Action","Origin"));
    sendRequest("../controller/controllerRutas.jsp",argsArray,showcityorigin);
}


function showcityorigin(){
    if (isValidResponse(this))
    {
        var res=this.responseText;
        if(res!="")
        {
            var info=eval("("+res+")");
            if(info.errorcode == 0)
            {
                if(info.data.length<1){
                    jConfirm('No existen Conductores  disponibles', 'Error', 'Error Dialog');
                }else{
                    var selF = document.getElementById("origin");
                    var selectF = "";
                    for(var i=0; i<info.data.length; i++){
                        selectF+='<option>';
                        selectF+=info.data[i].ori+'</option>';
                    }
                    selF.innerHTML = selectF;
                }

            }else
                jConfirm('No Found','Error', 'Error Dialog');
        }
    }

}

function citydestination(){
    var argsArray=new Array();
    argsArray.push(newArg("Action","Destination"));
    sendRequest("../controller/controllerRutas.jsp",argsArray,showcitydestination);
}


function showcitydestination(){
    if (isValidResponse(this))
    {
        var res=this.responseText;
        if(res!="")
        {
            var info=eval("("+res+")");
            if(info.errorcode == 0)
            {
                if(info.data.length<1){
                    jConfirm('No existen Conductores  disponibles', 'Error', 'Error Dialog');
                }else{
                    var selF = document.getElementById("destination");
                    var selectF = "";
                    for(var i=0; i<info.data.length; i++){
                        selectF+='<option>';
                        selectF+=info.data[i].des+'</option>';
                    }
                    selF.innerHTML = selectF;
                }

            }else
                jConfirm('No Found','Error', 'Error Dialog');
        }
    }

}

function loadInformation(){
   idvehicles();
    cityorigin();
   citydestination();
}